package ch.nostromo.tiffanys.engines.tiffanys.board.pieces;

import ch.nostromo.tiffanys.engines.tiffanys.board.TiffanysMove;
import ch.nostromo.tiffanys.game.board.Board;

public class TiffanysBishop extends TiffanysPiece {

  private static final int MY_PIECE_CODE = Board.PIECE_BISHOP;

  public static final int MATERIAL_VALUE = 300;

  public static int getMoveList(int currentPosition, int oldArrayLength, TiffanysMove[] moves, int[] enemyValues, boolean[] validMoveFields) {
    int arrayLength = oldArrayLength;
    int direction = +9;
    int counter = checkDirection(currentPosition, direction, validMoveFields, enemyValues);
    for (int i = 0; i < counter; i++) {
      int toField = currentPosition + ((i + 1) * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
        arrayLength++;
      }
      arrayLength++;
    }

    direction = -9;
    counter = checkDirection(currentPosition, direction, validMoveFields, enemyValues);
    for (int i = 0; i < counter; i++) {
      int toField = currentPosition + ((i + 1) * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
        arrayLength++;
      }
      arrayLength++;
    }

    direction = +11;
    counter = checkDirection(currentPosition, direction, validMoveFields, enemyValues);
    for (int i = 0; i < counter; i++) {
      int toField = currentPosition + ((i + 1) * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
        arrayLength++;
      }
      arrayLength++;
    }

    direction = -11;
    counter = checkDirection(currentPosition, direction, validMoveFields, enemyValues);
    for (int i = 0; i < counter; i++) {
      int toField = currentPosition + ((i + 1) * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      if (enemyValues[toField] != 0) {
        moves[arrayLength].hitmove = true;
        moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
        arrayLength++;
      }
      arrayLength++;
    }

    return arrayLength;

  }

  public static int getHitMoveList(int currentPosition, int oldArrayLength, TiffanysMove[] moves, int[] enemyValues, boolean[] validMoveFields) {
    int arrayLength = oldArrayLength;
    int direction = +9;
    int counter = checkHitDirection(currentPosition, direction, validMoveFields, enemyValues);
    if (counter > 0) {
      int toField = currentPosition + (counter * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength++;
    }

    direction = -9;
    counter = checkHitDirection(currentPosition, direction, validMoveFields, enemyValues);
    if (counter > 0) {
      int toField = currentPosition + (counter * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength++;
    }

    direction = +11;
    counter = checkHitDirection(currentPosition, direction, validMoveFields, enemyValues);
    if (counter > 0) {
      int toField = currentPosition + (counter * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength++;
    }

    direction = -11;
    counter = checkHitDirection(currentPosition, direction, validMoveFields, enemyValues);
    if (counter > 0) {
      int toField = currentPosition + (counter * direction);
      moves[arrayLength].setMove(currentPosition, toField, MY_PIECE_CODE);
      moves[arrayLength].hitmove = true;
      moves[arrayLength].hitScore = enemyValues[toField] - MATERIAL_VALUE;
      arrayLength++;
    }

    return arrayLength;

  }

}